package com.sr.recitewords.common.req;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.sr.recitewords.exception.BizException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;

@ApiModel("id入参公共req")
public class BaseIdReq<T> {

    @ApiModelProperty(value = "id")
    private T id;

    @ApiModelProperty(value = "ids")
    private List<T> ids;

    public T getId() {
        return id;
    }

    public void setId(T id) {
        this.id = id;
    }

    public List<T> getIds() {
        return ids;
    }

    public void setIds(List<T> ids) {
        this.ids = ids;
    }

    public List<T> getAllIds() {
        List<T> allIds = new ArrayList<>();
        if (ObjectUtils.isNotEmpty(id)) {
            allIds.add(id);
        }
        if (CollUtil.isNotEmpty(ids)) {
            allIds.addAll(ids);
        }
        if (CollUtil.isEmpty(allIds)) {
            throw new BizException("", "id或ids不能为空");
        }
        return allIds;
    }
}
